<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <!-- 数据列表 -->
    <div class="mt10">
      <el-card shadow="never" :body-style="{ padding: '10px' }">
        <div slot="header" class="mb9 f16">
          <span style="font-weight: 600">订单明细资料</span>
        </div>
        <Table :tableData="tableData" :tableHeader="tableHeader" :TableHeight="100" :outTableHeight="75" :summaryData="summaryData" summary />
        <!-- 分页器 -->
        <PageModule :PageData="{ total, buttonS: true }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
      </el-card>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, type Ref, computed } from 'vue'
import { reactive, ref } from 'vue'
import OrderSummary from '@/api/GeneralManager/inquire/OrderSummary'
import { TableList, selectList, type TableListType } from '@/plugins/mixin'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'OrderSummaryOle'
})
</script>

<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import Api from '@/api/GeneralManager/inquire/OrderSummary'
import { onMounted, watch } from 'vue'
import { debounce, forEach, throttle } from 'lodash'

// 初始化加载数据
onMounted(async () => {
  getTableList()
  getSelectList()
})
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入货号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '样品类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '季节',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'date',
    dateLabel: '客户交期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '下单日期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '出货日期',
    dateValue: ''
  },
  {
    type: 'checkbox',
    checked: true,
    checkboxLabel: '已完成'
  },
  {
    type: 'checkbox',
    checked: true,
    checkboxLabel: '未完成'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  }
])
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const tableData = ref([])
const imgList = ref<string[]>([])
const getTableList = debounce(async () => {
  let { Data, dataList, srcList } = (await TableList(formList, Api.getTableList, currentPage.value, pageSize.value)) as TableListType
  tableData.value = dataList
  total.value = Data.total
  imgList.value = srcList
  summaryData.value[0].num = Data.totalNum
}, 500)

const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}

const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)

const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
    getTableList()
  }
  if (content === '导出') {
    const res = (await fileRequest.post(`/pcOrder/downloadPcOrderHeadExcel`, {
      // deptName: formList15.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')?.treeValue,
      // name: formList15.value.find((item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名')?.inputValue,
      // sex: formList15.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')?.selectValue,
      // inTime: formList15.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期')?.dateValue?.[0],
      // outTime: formList15.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期')?.dateValue?.[1],
      // "pageNum": currentPage15.value,
      // "pageSize": pageSize15.value,
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    link.download = `订单汇总表${Date.now()}.xls` //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
}

interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 12,
    num: 0
  }
])

const getSelectList = async () => {
  await selectList(formList, Api.getSelectList)
}

const tableHeader = ref([
  {
    fixed: true,
    label: '品牌',
    prop: 'brand'
  },
  {
    fixed: true,
    label: '下单日期',
    prop: 'orderDate'
  },
  {
    fixed: true,
    label: '季节',
    prop: 'seasonType'
  },
  {
    fixed: true,
    label: '样品类型',
    prop: 'sampleType'
  },
  {
    fixed: true,
    type: 'img',
    prop: 'photoPath',
    label: '图片',
    srcList: imgList
  },
  {
    label: '指令号',
    prop: 'lotNo',
    width: '170'
  },
  {
    label: '客人货号',
    prop: 'custSTYLE',
    width: '100'
  },
  {
    label: '工厂货号',
    prop: 'style',
    width: '160'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '楦头',
    prop: 'lastNo'
  },
  {
    label: '大底',
    prop: 'moldNo',
    width: '150'
  },
  {
    label: '号码',
    prop: 'sizeNO'
  },
  {
    label: '数量',
    prop: 'orderQty'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '面衬',
    prop: 'sockNo'
  },
  {
    label: '客户交期',
    prop: 'deliveryDate'
  },
  {
    label: '出货日期',
    prop: 'closeDate'
  }
])
</script>

<style lang="less" scoped>
.btns {
  display: flex;
  justify-content: space-between;

  .bg {
    background-color: #e7e7e7;
    border: 1px solid #e7e7e7;
    color: #000000;
  }
}

// 底部
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10rem;

  .total {
    // font-size: 14px;
    color: rgba(0, 0, 0, 0.6);
    font-family: PingFangSC-Regular-, PingFangSC-Regular;
  }

  :deep(.el-pagination .el-select .el-input) {
    width: 60rem;
  }

  :deep(.number) {
    border: 1px solid #dcdcdc;
    box-sizing: border-box;
    margin-right: 4rem;
    border-radius: 2rem 2rem 2rem 2rem;
  }

  :deep(.is-active.number) {
    background-color: #f89027 !important;
    color: white;
    border-radius: 2rem 2rem 2rem 2rem;
  }

  .save {
    color: black;
    border: 1px solid #e7e7e7;
    background: #e7e7e7;
  }
}
</style>
